#include <cstdio>
using namespace std;

int c[10] = {0,1,5,10,50,100,500};
int a[10];

int main() {
	for (int i = 1; i <= 6; ++i) {
		scanf("%d", a + i);
	}
	int rest;
	scanf("%d", &rest);
	int ans = 0;
	for (int i = 6; i >= 1; ++i) {
		while (rest >= c[i] && a[i] > 0) {
			rest -= c[i];
			--a[i];
			++ans;
		}
	}
	printf("%d\n", ans);
	return 0;
}